﻿#include "treenavigation.h"
#include <QPushButton>
#include <QPainter>
#include <QTreeWidget>
#include <QDebug>
#include <QTextCodec>
#include <QScreen>
#include <QHeaderView>
#include <QScrollBar>
TreeNavigation::TreeNavigation(QWidget *parent) : QWidget(parent)
{
    setWindowFlags(Qt::FramelessWindowHint | Qt::CustomizeWindowHint);
    treeWidget = new QTreeWidget(this);
    treeWidget->setAnimated(true);
    treeWidget->setColumnCount(1);
    treeWidget->setHeaderHidden(true);
    treeWidget->resize(this->size());
    treeWidget->setIndentation(27);
    QScrollBar * v_scroll = treeWidget->verticalScrollBar();
    v_scroll->setContextMenuPolicy(Qt::NoContextMenu);
}

void TreeNavigation::resizeEvent(QResizeEvent *event)
{
    treeWidget->resize(this->width(), this->height()-30);//为了最后一行显示出来，我也不知道为什么不减去点长度就显示有问题
    qDebug()<<this->size()<<endl;
}

void TreeNavigation::addNode(QString nodeName, QStringList nodeChildName)
{
    items.append(new QTreeWidgetItem((QTreeWidget*)0, QStringList(nodeName)));
    if (!nodeChildName.isEmpty()){
        QTreeWidgetItem *lastItem =items.last();
        foreach (QString name, nodeChildName) {
            lastItem->addChild(new QTreeWidgetItem(lastItem, QStringList(name)));
        }
    }
    treeWidget->addTopLevelItems(items);
}

//void TreeNavigation::paintEvent(QPaintEvent *event)
//{
////   QPainter painter(this);
////   painter.fillRect(this->rect(), QColor(36, 173, 243, 255));
//}
